﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Security;
using AncientLand.Service.Entity;

namespace AncientLand.Controllers.Admin
{
   public class AdminController: Controller
    {
       public ActionResult Login()
       {
           return View();
       }

       
       [HttpPost]
       public ActionResult Login(FormCollection forms, string returnUrl)
       {
           string name =forms["username"];
           string password = forms["password"];
           string remember = forms["rememberMe"];
           Boolean isRemember = !string.IsNullOrEmpty(remember) && remember != "on" ? false : true;
           //password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1");
           if (FormsAuthentication.Authenticate(name, password))
           {
               FormsAuthentication.SetAuthCookie(name, isRemember);
               return Redirect(!String.IsNullOrEmpty(returnUrl) ? returnUrl : FormsAuthentication.DefaultUrl);
           }
           else
               ViewBag.Error="用户名或密码不正确！";

           return View();
       }

       [Authorize]
       public ActionResult Default()
       {
           return View();
       }

       [Authorize]
       public ActionResult HomePageImages()
       {
           return View();
       }

       [Authorize]
       public ActionResult LogOff()
       {
           FormsAuthentication.SignOut();

           return RedirectToAction("Login", "Admin");
       }
    }
}
